package com.sxhuayuan.parking.dao;

import com.sxhuayuan.parking.entity.Agent;
import com.sxhuayuan.parking.entity.MonthlyProfit;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.List;

/**
 * 代理分润月结算
 * @author 何龙
 * @create 2019-05-22 17:28
 */
public interface MonthlyProfitDao extends BaseDao<MonthlyProfit, Long> {


	/** 根据代理和月份查询代理分润月结算 */
	@Query(value = "select m from MonthlyProfit m where m.agent=?1 and m.statistisMonth>=?2 and m.statistisMonth<=?3")
	List<MonthlyProfit> findByAgentAndMonth(Agent agent, LocalDate start, LocalDate end);

	/** 根据代理id删除代理对应的月分润统计 */
	@Transactional
	@Modifying
	@Query("delete from MonthlyProfit m where m.agent.id=?1")
	void deleteByAgentId(Long id);
}
